package org.apache.rocketmq.store.logfile;

import org.apache.rocketmq.common.message.MessageExtBatch;
import org.apache.rocketmq.common.message.MessageExtBrokerInner;
import org.apache.rocketmq.store.*;
import org.apache.rocketmq.store.config.FlushDiskType;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Iterator;


public interface MappedFile {

    String getFileName();

    boolean renameTo(String fileName);

    int getFileSize();

    FileChannel getFileChannel();

    boolean isFull();

    boolean isAvailable();

    AppendMessageResult appendMessage(MessageExtBrokerInner message, AppendMessageCallback messageCallback, PutMessageContext putMessageContext);

    AppendMessageResult appendMessages(MessageExtBatch message, AppendMessageCallback messageCallback, PutMessageContext putMessageContext);

    AppendMessageResult appendMessage(final ByteBuffer byteBufferMsg, final CompactionAppendMsgCallback cb);

    boolean appendMessage(byte[] data);

    boolean appendMessage(ByteBuffer data);

    boolean appendMessage(byte[] data, int offset, int length);

    long getFileFromOffset();

    int flush(int flushLeastPages);

    int commit(int commitLeastPages);

    SelectMappedBufferResult selectMappedBuffer(int pos, int size);

    SelectMappedBufferResult selectMappedBuffer(int pos);

    MappedByteBuffer getMappedByteBuffer();

    ByteBuffer sliceByteBuffer();

    long getStoreTimestamp();

    long getLastModifiedTimestamp();

    boolean getData(int pos, int size, ByteBuffer byteBuffer);

    boolean destroy(long intervalForcibly);

    void shutdown(long intervalForcibly);

    void release();

    boolean hold();

    boolean isFirstCreateInQueue();

    void setFirstCreateInQueue(boolean firstCreateInQueue);

    int getFlushedPosition();

    void setFlushedPosition(int flushedPosition);

    int getWrotePosition();

    void setWrotePosition(int wrotePosition);

    int getReadPosition();

    void setCommittedPosition(int committedPosition);

    void mlock();

    void munlock();

    void warmMappedFile(FlushDiskType type, int pages);

    boolean swapMap();

    void cleanSwapedMap(boolean force);

    long getRecentSwapMapTime();

    long getMappedByteBufferAccessCountSinceLastSwap();

    File getFile();

    void renameToDelete();

    void moveToParent() throws IOException;

    long getLastFlushTime();

    void init(String fileName, int fileSize, TransientStorePool transientStorePool) throws IOException;

    Iterator<SelectMappedBufferResult> iterator(int pos);

    boolean isLoaded(long position, int size);
}
